package com.erp.wallet.controller;

import com.erp.wallet.domain.bo.ErpSellerStoreWalletLogBo;
import com.erp.wallet.domain.vo.ErpSellerStoreWalletLogVo;
import com.erp.wallet.service.IErpSellerStoreWalletLogService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.wallet.api.domain.ErpSellerStoreWalletLog;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * erp用户钱包日志
 *
 * @author erp
 * @date 2023-05-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerStoreWalletLog")
public class ErpSellerStoreWalletLogController extends BaseController {

    private final IErpSellerStoreWalletLogService iErpSellerStoreWalletLogService;

    /**
     * 根据订单号获取钱包日志
     */
    @GetMapping("/getWalletLogByOrderNumber")
    public ErpSellerStoreWalletLog getWalletLogByOrderNumber(@RequestParam("orderNumber") String orderNumber) {
        return iErpSellerStoreWalletLogService.getWalletLogByOrderNumber(orderNumber);
    }

    /**
     * 查询erp用户钱包日志列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpSellerStoreWalletLogVo> list(ErpSellerStoreWalletLogBo bo, PageQuery pageQuery) {

    	// 获取当前登陆用户
    	Long sellerId = SecurityUtils.getUserId();
//    	Long sellerId = 1l;
    	bo.setSellerId(sellerId);

        return iErpSellerStoreWalletLogService.queryPageList(bo, pageQuery);
    }

    @GetMapping("/queryEvaluationLog")
    public TableDataInfo<ErpSellerStoreWalletLogVo> queryEvaluationLog(ErpSellerStoreWalletLogBo bo, PageQuery pageQuery) {

        Long userId = SecurityUtils.getUserId();
//        bo.setCreateBy(userId.toString());
        bo.setExpenseType(14);

        return iErpSellerStoreWalletLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出erp用户钱包日志列表
     */
    @PostMapping("/export")
    public void export(ErpSellerStoreWalletLogBo bo, HttpServletResponse response) {
        List<ErpSellerStoreWalletLogVo> list = iErpSellerStoreWalletLogService.queryList(bo);
        ExcelUtil<ErpSellerStoreWalletLogVo> excelUtil = new ExcelUtil<>(ErpSellerStoreWalletLogVo.class);
        excelUtil.exportExcel(response,list,"erp用户钱包日志");
    }

    /**
     * 获取erp用户钱包日志详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpSellerStoreWalletLogVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpSellerStoreWalletLogService.queryById(id));
    }

    /**
     * 新增erp用户钱包日志
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerStoreWalletLogBo bo) {
        return toAjax(iErpSellerStoreWalletLogService.insertByBo(bo));
    }

    /**
     * 修改erp用户钱包日志
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerStoreWalletLogBo bo) {
        return toAjax(iErpSellerStoreWalletLogService.updateByBo(bo));
    }

    /**
     * 删除erp用户钱包日志
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerStoreWalletLogService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
